<template>
  <a-card :bordered="false">
    <a-tabs v-model="bizTaskType" @change="handleChangeTabs">
      <a-tab-pane key="0" tab="所有通知单">
      </a-tab-pane>
      <a-tab-pane key="1">
        <span slot="tab">
          <a-badge :count="doTotal">
            待我处理&nbsp;&nbsp;&nbsp;
          </a-badge>
        </span>
      </a-tab-pane>
      <a-tab-pane key="2" tab="我发起的">
        <!--<span slot="tab">
          <a-badge :count="myTotal">
            我发起的&nbsp;&nbsp;&nbsp;
          </a-badge>
        </span>-->
      </a-tab-pane>
    </a-tabs>
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="开票申请编号">
              <a-input placeholder="请输入开票申请编号" v-model="queryParam.invoiceApplyNo"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="申请人">
              < placeholder="请输入申请人" v-model="queryParam.applyUser"></>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="销售方单位">
                <a-input placeholder="请输入销售方单位" v-model="queryParam.saleUnit"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="开票人">
                < placeholder="请输入开票人" v-model="queryParam.invoiceUser"></>
              </a-form-item>
            </a-col>
            <a-col :xl="10" :lg="11" :md="12" :sm="24">
              <a-form-item label="开票日期">
                <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam.invoiceDate_begin"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam.invoiceDate_end"></j-date>
              </a-form-item>
            </a-col>
            <a-col :xl="10" :lg="11" :md="12" :sm="24">
              <a-form-item label="开票金额">
                <a-input placeholder="请输入最小值" class="query-group-cust"
                         v-model="queryParam.invoiceAmount_begin"></a-input>
                <span class="query-group-split-cust"></span>
                <a-input placeholder="请输入最大值" class="query-group-cust" v-model="queryParam.invoiceAmount_end"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="发票类型">
                <a-input placeholder="请输入发票类型" v-model="queryParam.invoiceType"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="是否确认收票">
                <j-dict-select-tag placeholder="请选择是否确认收票" v-model="queryParam.confirmInvoice" dictCode="yes_no"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="是否关联项目">
                <j-dict-select-tag placeholder="请选择是否关联项目" v-model="queryParam.hasRelatedProject" dictCode="yes_no"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="经办人编号">
                < placeholder="请输入经办人编号" v-model="queryParam.handlerId"></>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="经办人部门ID">
                <a-input placeholder="请输入经办人部门ID" v-model="queryParam.handlerDeptId"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAddDiy" type="primary" icon="plus"
                :disabled="isDisabledAuth('erpFinanceInvoiceManager:add')">新增
      </a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('开票申请管理')"
                :disabled="isDisabledAuth('erpFinanceInvoiceManager:export')">导出
      </a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
                @change="handleImportExcel">
        <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpFinanceInvoiceManager:import')">导入
        </a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpFinanceInvoiceManager:delete')">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12">
                    <a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox>
                  </a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;">
          <a-icon type="setting" :style="iconStyle"/>
        </a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
        style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <span slot="notify" slot-scope="text, record">
          <a-icon title="催办提醒" v-if="record.taskUrge" theme="twoTone" twoToneColor="#eb2f96"
                  @click="taskNotifyMe(flowCode,record.id)" type="notification"/>
          {{ text }}
        </span>
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
            <template v-if="record.bpmStatus === '1'">
            <a-button
              class="ruleButton"
              :ghost="true"
              type="primary"
              icon="edit"
              @click="handleEdit(record)"
              :disabled="isDisabledAuth('erpFinanceInvoiceManager:edit')"
            />
            <a-divider type="vertical"/>
            <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                <a-button
                  class="ruleButton"
                  :ghost="true"
                  type="primary"
                  icon="delete"
                  :disabled="isDisabledAuth('erpFinanceInvoiceManager:delete')"/>
            </a-popconfirm>
            <a-divider type="vertical"/>
            <a-button type="primary" size="small" @click="startProcess(record)"
                      :disabled="isDisabledAuth('erpFinanceInvoiceManager:startProcess')">发起流程</a-button>
        </template>
        <template v-else-if="showBtn(record.bpmStatus)&&queryParam.bizTaskType=='1'">
            <a-button type="primary" size="small" @click="handleProcess(record)">办理</a-button>
            <a-divider type="vertical"/>
        </template>
        <template v-else-if="queryParam.bizTaskType=='2' && showBtn(record.bpmStatus)">
            <a-button type="primary" size="small" @click="taskNotify(flowCode,record.id)">催办</a-button>
            <a-divider type="vertical"/>
            <a-popconfirm title="确定要作废吗?" @confirm="() => invalidProcess(record)">
                <a-button type="primary" size="small"
                          :disabled="isDisabledAuth('erpFinanceInvoiceManager:invalidProcess')">
                    作废流程
                </a-button>
            </a-popconfirm>
            <a-divider type="vertical"/>
        </template>
        <template v-if="record.bpmStatus !== '1'">
            <a-button type="primary" size="small" @click="handleTrack(record)"
                      :disabled="isDisabledAuth('erpFinanceInvoiceManager:viewTrack')">审批进度</a-button>
        </template>
        </span>

      </a-table>
    </div>

    <erp-finance-invoice-manager-modal ref="modalForm" @ok="modalFormOk"></erp-finance-invoice-manager-modal>
    <bpm-biz-task-deal-modal ref="taskDealModal" :path="path" :formData="formData"
                             @ok="handleOk"></bpm-biz-task-deal-modal>
    <bpm-process-track-modal ref="bpmProcessTrackModal"></bpm-process-track-modal>
    <biz-task-notify-modal ref="taskNotifyModal"></biz-task-notify-modal>
    <biz-task-notify-me-modal ref="taskNotifyMeModal"></biz-task-notify-me-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgBpmListMixin } from '@/mixins/JeecgBpmListMixin'
import BpmBizTaskDealModal from '@/views/modules/bpmbiz/common/BpmBizTaskDealModal.vue';
import BpmProcessTrackModal from '@/views/modules/bpmbiz/common/BpmProcessTrackModal.vue';
import BizTaskNotifyModal from '@/views/modules/bpmbiz/common/BizTaskNotifyModal.vue';
import BizTaskNotifyMeModal from '@/views/modules/bpmbiz/common/BizTaskNotifyMeModal.vue';
import ErpFinanceInvoiceManagerModal from './modules/ErpFinanceInvoiceManagerModal'
import { httpAction } from '@/api/manage'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'

export default {
  name: 'ErpFinanceInvoiceManagerList',
  mixins: [JeecgBpmListMixin, mixinDevice, DisabledAuthFilterMixin],
  components: {
    ErpFinanceInvoiceManagerModal,
    BpmBizTaskDealModal,
    BpmProcessTrackModal,
    BizTaskNotifyModal,
    BizTaskNotifyMeModal,
    SelectUserByDep,
  },
  data() {
    return {
      description: '开票申请管理管理页面',
      //表头
      columns: [],
      //列设置
      settingColumns: [],
      // 列定义
      defColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '经办人编号',
          align: 'center',
          dataIndex: 'handlerId',
        },
        {
          title: '经办人部门ID',
          align: 'center',
          dataIndex: 'handlerDeptId',
        },
        {
          title: '是否已删除',
          align: 'center',
          dataIndex: 'delFlag',
        },
        {
          title: '开票申请编号',
          align: 'center',
          dataIndex: 'invoiceApplyNo',
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'applyUser',
        },
        {
          title: '销售方单位',
          align: 'center',
          dataIndex: 'saleUnit',
        },
        {
          title: '开票金额',
          align: 'center',
          dataIndex: 'invoiceAmount',
        },
        {
          title: '是否确认收票',
          align: 'center',
          dataIndex: 'confirmInvoice_dictText',
        },
        {
          title: '是否关联项目',
          align: 'center',
          dataIndex: 'hasRelatedProject_dictText',
        },
        {
          title: '开票人',
          align: 'center',
          dataIndex: 'invoiceUser',
        },
        {
          title: '开票日期',
          align: 'center',
          dataIndex: 'invoiceDate',
          customRender: function (text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'bpmStatus',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ],
      url: {
        list: '/api/erp/finance/invoice/erpFinanceInvoiceManager/list',
        delete: '/api/erp/finance/invoice/erpFinanceInvoiceManager/delete',
        deleteBatch: '/api/erp/finance/invoice/erpFinanceInvoiceManager/deleteBatch',
        exportXlsUrl: '/api/erp/finance/invoice/erpFinanceInvoiceManager/exportXls',
        importExcelUrl: 'api/erp/finance/invoice/erpFinanceInvoiceManager/importExcel',
        bizCount: '/api/erp/finance/invoice/erpFinanceInvoiceManager/bizCount',
        queryAddParameter: '/api/erp/omc/tenderfile/erpOmcTenderFile/queryAddParameter',
      },
      //代码生成后需手动设置流程编码
      flowCode: 'dev_erp_finance_invoice_manager_001',
      formUrl: 'scy/finance/invoice/modules/ErpFinanceInvoiceManagerForm',
      formUrlMobile: '',
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    initDictConfig() {
    },
    handleAddDiy() {
      let httpurl = '';
      let method = '';
      httpurl += this.url.queryAddParameter;
      method = 'POST';
      httpAction(httpurl, this.model, method).then((res) => {
        this.$nextTick(() => {
          this.$refs.modalForm.add(res.result);
          this.$refs.modalForm.title = '新增';
          this.$refs.modalForm.disableSubmit = false;
        })
      })
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'handlerId', text: '经办人编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'handlerDeptId', text: '经办人部门ID', dictCode: '' })
      fieldList.push({ type: 'int', value: 'delFlag', text: '是否已删除', dictCode: 'yes_no,,' })
      fieldList.push({ type: 'string', value: 'invoiceApplyNo', text: '开票申请编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'applyUser', text: '申请人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'saleUnit', text: '销售方单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'invoiceAmount', text: '开票金额', dictCode: '' })
      fieldList.push({ type: 'string', value: 'amountInWords', text: '大写', dictCode: '' })
      fieldList.push({ type: 'string', value: 'invoiceType', text: '发票类型', dictCode: 'invoice_type' })
      fieldList.push({ type: 'string', value: 'confirmInvoice', text: '是否确认收票', dictCode: 'yes_no' })
      fieldList.push({ type: 'string', value: 'hasRelatedProject', text: '是否关联项目', dictCode: 'yes_no' })
      fieldList.push({ type: 'string', value: 'invoiceUser', text: '开票人', dictCode: '' })
      fieldList.push({ type: 'date', value: 'invoiceDate', text: '开票日期' })
      fieldList.push({ type: 'string', value: 'purchasingUnit', text: '购货方单位名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'taxpayerRegistrationNumber', text: '纳税人识别号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'addressPhone', text: '地址、电话', dictCode: '' })
      fieldList.push({ type: 'string', value: 'openingBankAccountNumber', text: '开户行及账号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'invoiceRemark', text: '发票备注', dictCode: '' })
      fieldList.push({ type: 'string', value: 'postscript', text: '附言', dictCode: '' })
      fieldList.push({ type: 'string', value: 'fileUpload', text: '附件', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bpmStatus', text: '状态', dictCode: '' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
